# -*- Mode: makefile -*-

BUILD_DIR?=$(CURDIR)/..

include ../config-host.mak
include config-target.mak
include $(SRC_PATH)/rules.mak

ifdef CONFIG_SOFTMMU
include config-devices.mak
endif

$(call set-vpath, $(SRC_PATH):$(BUILD_DIR))
ifdef CONFIG_LINUX
QEMU_CFLAGS += -I../linux-headers
endif
QEMU_CFLAGS += -iquote .. -iquote $(SRC_PATH)/target/$(TARGET_BASE_ARCH) -DNEED_CPU_H

QEMU_CFLAGS+=-iquote $(SRC_PATH)/include
# system emulator name
QEMU_PROG=qemu-system-$(TARGET_NAME)$(EXESUF)
QEMU_PROG_BUILD = $(QEMU_PROG)

PROGS=$(QEMU_PROG) $(QEMU_PROGW)
STPFILES=

config-target.h: config-target.h-timestamp
config-target.h-timestamp: config-target.mak

config-devices.h: config-devices.h-timestamp
config-devices.h-timestamp: config-devices.mak
ifdef CONFIG_USER_ONLY
TARGET_TYPE=user
else
TARGET_TYPE=system
endif
.PHONY: stap

all: $(PROGS) stap

# Dummy command so that make thinks it has done something
	@true

#########################################################
# cpu emulator library
obj-y += exec.o exec-vary.o
obj-y += accel/
obj-$(CONFIG_TCG) += tcg/tcg.o tcg/tcg-op.o
obj-$(CONFIG_TCG) += tcg/tcg-common.o tcg/optimize.o
obj-y += target/$(TARGET_BASE_ARCH)/
obj-y += disas.o
LIBS := $(libs_cpu) $(LIBS)
# System emulator target
ifdef CONFIG_SOFTMMU
obj-y += arch_init.o cpus.o ioport.o
obj-y += qtest.o
obj-y += hw/
obj-y += monitor/
obj-y += qapi/
obj-y += memory.o
LIBS := $(libs_softmmu) $(LIBS)

# Hardware support
ifeq ($(TARGET_NAME), sparc64)
obj-y += hw/sparc64/
else
obj-y += hw/$(TARGET_BASE_ARCH)/
endif
generated-files-y += config-devices.h

endif # CONFIG_SOFTMMU

dummy := $(call unnest-vars,,obj-y)
all-obj-y := $(obj-y)

include $(SRC_PATH)/Makefile.objs
dummy := $(call unnest-vars,.., \
               authz-obj-y \
               block-obj-y \
               block-obj-m \
               chardev-obj-y \
               crypto-obj-y \
               crypto-user-obj-y \
               qom-obj-y \
               io-obj-y \
               common-obj-y \
               common-obj-m)
all-obj-y += $(common-obj-y)
all-obj-y += $(qom-obj-y)
all-obj-$(CONFIG_SOFTMMU) += $(authz-obj-y)
all-obj-$(CONFIG_SOFTMMU) += $(block-obj-y) $(chardev-obj-y)
all-obj-$(CONFIG_USER_ONLY) += $(crypto-user-obj-y)
all-obj-$(CONFIG_SOFTMMU) += $(crypto-obj-y)
all-obj-$(CONFIG_SOFTMMU) += $(io-obj-y)

ifdef CONFIG_SOFTMMU
$(QEMU_PROG_BUILD): config-devices.mak
endif

COMMON_LDADDS = ../libqemuutil.a

# build either PROG or PROGW
$(QEMU_PROG_BUILD): $(all-obj-y) $(COMMON_LDADDS)
	$(call LINK, $(filter-out %.mak, $^))

generated-files-y += config-target.h
Makefile: $(generated-files-y)
